package LeetCode.month02.day51;

import LeetCode.month02.day50.ListNode;

public class No92 {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode newhead = new ListNode(0,head);
        ListNode preleft = head;
        for (int i = 1; i < left; i++) {
            preleft = preleft.next;
        }
        ListNode curr = preleft.next;
        ListNode pre = null;
        for (int i = 0; i < right-left+1; i++) {
            ListNode next = curr.next;
            curr.next = pre;
            pre = curr;
            curr = next;
        }
        preleft.next.next = curr;
        preleft.next = pre;
        return newhead.next;
    }

}
